<%--
  @author Duminda Dharmakeerthi
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<script type="text/javascript">
    $(document).ready(function () {
        $('.land-table').dataTable({
            "sPaginationType":"full_numbers",
            "bDestroy":true,
            "oLanguage":{
                "sZeroRecords":$('#no-record').val(),
                "sLengthMenu":$('#display').val() + " _MENU_ " + $('#records').val(),
                "sSearch":$('#search').val(),
                "sInfo":$('#showing').val() + " _START_ " + $('#to').val() + " _END_ " + $('#of').val() + " _TOTAL_ " + $('#entries').val(),
                "sInfoEmpty":$('#no-record').val(),
                "oPaginate":{
                    "sFirst":$('#first').val(),
                    "sLast":$('#last').val(),
                    "sNext":$('#next').val(),
                    "sPrevious":$('#previous').val()
                }
            },
            "fnDrawCallback":function () {
                if ($('.dataTables_paginate span span.paginate_button').size()) {
                    $('.dataTables_paginate')[0].style.display = "block";
                } else {
                    $('.dataTables_paginate')[0].style.display = "none";
                }
            }
        });
    });


    function viewLandDetails(landId) {
        //ajax find land list by parent id
        var url = '${"findClildrenByParentLand.do?landId=' + landId + '"}';
        $.get(url, $(this).serialize(), function(data) {
            $("#landDetails").html(data);
            //if list contain only one element display land details
            //else
            //display in tree
        });
    }


</script>

<div id="land-registration-module-home-title" class="module-home-title">
    <s:a href="searchModule.do"><img src="${pageContext.request.contextPath}/images/search.png"
                                     alt="Land Alienation"><span><s:label
            value="%{getText('search.label')}"/></span></s:a>
    <span class="module-title-breaker"> > </span>
    <s:a href="searchLandsByAlienationType.do"><img
            src="${pageContext.request.contextPath}/images/searchLand.png"><span><s:label
            value="%{getText('search_lands_by_alienation.label')}"/></span></s:a>
    <div id="back-button" align="right">
                <s:form><s:submit value="%{getText('back_btn.label')}" action="searchModule"/></s:form>
    </div>
</div>

<div class="page-title">
    <h2><s:label value="%{getText('search_lands_by_alienation.label')}"/></h2>
</div>
<div id="search-lands-form-outer">
    <s:form id="lands-by-alienation-type" name="lands-by-alienation-type">
        <table class="width-100">
            <tr>
                <td><s:label value="%{getText('alienation_method.label')}"/></td>
                <td><s:select list="alienationTypeList" id="alienation-type" name="alienationType"
                              headerValue="%{getText('all.label')}" headerKey="0"/></td>
                <td><s:submit value="%{getText('search.label')}" action="searchLandsByAlienationType"/></td>
            </tr>
        </table>
    </s:form>
</div>

<table id="alienation-table" class="width-100 margin-10-auto table land-table">
    <thead>
    <tr>
        <th><s:label value="%{getText('reference_no.label')}"/></th>
        <th><s:label value="%{getText('name_of_the_land.label')}"/></th>
        <th><s:label value="%{getText('name_of_holder.label')}"/></th>
        <th><s:label value="%{getText('plan_no.label')}"/></th>
        <th><s:label value="%{getText('lot_no.label')}"/></th>
        <th><s:label value="%{getText('action.label')}"/></th>
    </tr>
    </thead>
    <tbody>
    <s:iterator status="alienations" value="alienationList">
        <tr>
            <td><s:property value="referenceNo"/></td>
            <td><s:property value="land.nameOfTheLand"/></td>
            <td><s:property value="holder.name"/></td>
            <td><s:property value="land.planNumber"/></td>
            <td><s:property value="land.lotNumber"/></td>
              <%-- <td><a tooltip="Edit" href="printDetailLandInformation.do?landId="><s:property value="land.id"/> <img src="${pageContext.request.contextPath}/images/detailed-form.png" style="border:none; width:25px; height:25px;"/> </a></td>--%>
            <td class="center-align">
                <%--<s:url id="printDetail" action="printDetailLandInformation">
                    <s:param name="landId" value="land.id"/>
                </s:url>
                <s:a href="%{printDetail}" title="%{getText('view_tooltip.label')}">
                    <img src="<s:url value='/images/detailed-form.png'/>" border="none" width="25"
                         height="25"/>
                </s:a>--%>
                <a href="#" title="View" id="viewLink"
                                                     onclick="viewLandDetails('<s:property value="land.id"/>')">
                <img src="${pageContext.request.contextPath}/images/detailed-form.png" style="border:none; width:25px; height:25px;"/> </a>
            </td>

            <%--<td width="80px" class="center-align"><a href="#" title="View" id="viewLink"
                                                     onclick="viewLandDetails('<s:property value="id"/>')">
                <img src="${pageContext.request.contextPath}/images/detailed-form.png" style="border:none; width:25px; height:25px;"/> </a></td>

--%>
        </tr>
    </s:iterator>
    </tbody>
</table>

<div id="landDetails">

</div>

<%-- Localization text for data tables --%>
<s:hidden id="display" value="%{getText('display.label')}"/>
<s:hidden id="records" value="%{getText('records.label')}"/>
<s:hidden id="search" value="%{getText('search.label')}"/>
<s:hidden id="no-record" value="%{getText('no_record.label')}"/>
<s:hidden id="showing" value="%{getText('showing.label')}"/>
<s:hidden id="to" value="%{getText('to.label')}"/>
<s:hidden id="of" value="%{getText('of.label')}"/>
<s:hidden id="entries" value="%{getText('entries.label')}"/>
<s:hidden id="first" value="%{getText('first.label')}"/>
<s:hidden id="last" value="%{getText('last.label')}"/>
<s:hidden id="next" value="%{getText('next.label')}"/>
<s:hidden id="previous" value="%{getText('previous.label')}"/>

